﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.Project;
using Jzy.Model.Project;
using Jzy.Model.Mail;

using Jzy.BLL.Mail;
using Frame.Lib.Common;
using Frame.Lib.Utilities;

public partial class Project_Oversee_Edit : PageEdit
{
    private string TaskID
    {
        get
        {
            return Request["TaskID"];
        }
    }
    private string PrjID
    {
        get
        {
            return Request["PrjID"];
        }
    }
    private PrjTaskBO _task;
    protected void Page_Load(object sender, EventArgs e)
    {
        _task = new PrjTaskBO(int.Parse(PrjID));
        if (!IsPostBack)
        {
            PrjTaskInfo info = _task.GetInfo(TaskID);
            lblTaskName.Text = info.Name;
            lblUserNames.Text = info.UserNames;            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        TaskOverseeBO oversee = new TaskOverseeBO(TaskID);
        TaskOverseeInfo info = new TaskOverseeInfo();
        info.InputTime = DateTime.Now;
        info.Remark = txtRemark.Text;
        info.TaskID = int.Parse(TaskID);
        info.UserID = AppSession.UserID;
        info.UserName = AppSession.UserName;
        oversee.Save(info);

        PrjTaskInfo taskInfo = _task.GetInfo(TaskID);

        if (chkMail.Checked)
        {
            if (taskInfo.UserIDs != "")
            {

                MailInfo mailInfo = new MailInfo();
                mailInfo.CreatorID = AppSession.UserID;
                mailInfo.CreatorName = AppSession.UserName;
                mailInfo.InputTime = DateTime.Now;
                mailInfo.Name = "项目督办提醒";
                string prjName = (new ProjectBO()).GetName(PrjID);
                mailInfo.Content = "<div style='font-weight:bold;padding:10px 0px 10px 10px;'>项目：[" + prjName + "]=>[" + taskInfo.Name + "]</div>" +
                                   "<div style='padding:10px 0px 10px 10px;'>=========下面是督办内容==========</div>" +
                                   "<div style='padding:10px 0px 10px 10px;'>" + info.Remark + "</div>" +
                                   "<div style='padding:10px 0px 10px 10px;'>===============================</div>";
                mailInfo.RecieveIDs = "-" + taskInfo.UserIDs.Replace(",", ",-"); ;//用户ID要为负的
                mailInfo.RecieveNames = taskInfo.UserNames;

                MailBO mail = new MailBO(AppSession.UserID);
                mail.Send(mailInfo, null, WriteMailMode.New);
            }
        }

        string script = "top.setTimeout(\"alert('督办成功')\",100);" +JSUtil.GetDelFrmString();
        JSUtil.ResponseJS(script);
        
    }
}
